(function(){
	var pagenum=10;//每页数量
	var curpage=1;//当前页面
	var totalPage=0;//总页数
	//获取列表
	function getlist(curpage,pagenum){
	   $.ajax({
			url:'http://web.icecn.net/user/getWebWealthList.json',
			type:'get',
			async:true,
			data:{
                offset:pagenum*(curpage-1),
				limit:pagenum,
			},
			xhrFields:{withCredentials:true},
			dataType: "json",
			success: function(data){
				if(data.code === 200 ){
				    dataset=data.t.result;
					if(dataset && dataset.length > 0){
						for(var i=0;i<dataset.length;i++){
							dataset[i].applyTime=getMyDate(dataset[i].applyTime)
						}
					   var html = template('datalist',{dataset:dataset});
					   $("#example1").html(html);
					   totalPage=data.t.totalPage;
					   $(".pageinfo").html("当前"+curpage+"页/共"+totalPage+"页");
					   $(".curpage").val(curpage);
					   if(curpage==1){$(".prev").addClass("disabled")}else{$(".prev").removeClass("disabled")}
					   if(curpage==totalPage){$(".next").addClass("disabled")}else{$(".next").removeClass("disabled")}
					};
				}
			}
	   });
	}
	var Page = {
		init:function(){
			this.render();
			this.event();
		},
		//绑定事件
		event:function(){
			//上一页
		    $(".prev").click(
			    function(){
					if(curpage>1){
				     	curpage=curpage-1;
					    getlist(curpage,pagenum);
					}
			    }
			)
			//下一页
		    $(".next").click(
			    function(){
					if(curpage<totalPage){
				     	curpage=curpage+1;
					    getlist(curpage,pagenum);
					}
			    }
			)
			//页码跳转
			$(".gopage").click(
			    function(){
					if($(".curpage").val()>=1&&$(".curpage").val()<=totalPage){
				    	curpage=parseInt($(".curpage").val());
					    getlist(curpage,pagenum)
					}else{
						$(".curpage").val(curpage);
					}
			    }
			)
			$(".content-wrapper").on("click", '.Set', function() {
				var taskId=$(this).attr("data-id")
				var handleType=$(this).attr("data-is")
				var msg=handleType==1?"确认批准吗？":"确认拒绝吗？"
				if (confirm(msg)==true){ 
				   $.ajax({
						url:'http://web.icecn.net/user/handleWebWeanth.json',
						type:'post',
						async:true,
						data:{
							taskId:taskId,
							handleType:handleType,
						},
						dataType: "json",
		             	xhrFields:{withCredentials:true},
						success: function(data){
							if(data.code === 200 ){
								getlist(curpage,pagenum)
							}else{
							  alert(data.msg)	
							}
						}
				   });
				}else{ 
				  return false; 
				} 
			})
		},
		//渲染页面
		render:function(){
			getlist(curpage,pagenum)
		}
	};
	Page.init();
})();